$def with (work, edition)

$ username = ctx.user and ctx.user.key.split('/')[-1]
$ rating = work and username and work.get_users_rating(username)
$ edition_key = edition.key if edition else ""

<form id="ratingsForm" method="POST" action="$(work.key)/ratings.json"
      property="reviewRating" typeof="Rating" vocab="http://schema.org/" typeof="Books">
  <meta property="worstRating" content="1"/>
  <meta property="bestRating" content="5"/>
  <input type="hidden" value="$edition_key" name="edition_id"/>
  <input type="hidden" value="true" name="redir"/>
  <div class="stars">
    $ NUM_STARS = 5
    $for star in range(1, NUM_STARS + 1)
      <input type="submit" value="$star" name="rating"
        $if rating == star:
          class="star-$star star-selected"
        $else:
          class="star-$star"
        id="star-$star" />
      <label class="star star-$star $('star-selected' if rating==star else '')"
        $ properties = []
        $if star == rating:
          $ properties.append("ratingValue")
        $if star == 1:
          $ properties.append("worstRating")
        $elif (star == NUM_STARS):
          $ properties.append("bestRating")
        $if properties:
          property="$(' '.join(properties))"
        for="star-$star">$star</label>
    <span></span>
  </div>
  $if rating:
      <button type="submit" class="star-messaging">$_("Clear my rating")</button>
</form>
